package net.zoneland.zrdp.common.filter;


import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import java.io.ByteArrayInputStream;

public class RepeatedlyServletInputStream extends ServletInputStream {
    private final ByteArrayInputStream sourceStream;
    private final int bodyLength;

    public RepeatedlyServletInputStream(final ByteArrayInputStream sourceStream, final int bodyLength) {
        this.sourceStream = sourceStream;
        this.bodyLength = bodyLength;
    }


    @Override
    public int read()
    {
        return sourceStream.read();
    }

    @Override
    public synchronized void reset() {
        sourceStream.reset();
    }

    @Override
    public int available()
    {
        return bodyLength;
    }

    @Override
    public boolean isFinished()
    {
        return false;
    }

    @Override
    public boolean isReady()
    {
        return false;
    }

    @Override
    public void setReadListener(ReadListener readListener)
    {
        // Do nothing
    }
}
